﻿<%@ Page Title="monitorToolsNum" Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="cebao.Web.monitorToolsNum.List" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="../Script/json2.js"></script>
     <script type="text/javascript">
         var cadd = "";
         $(function () {
             InitSearch();
             InitGird();
             
         });
         //初始化表格
         function InitGird() {
             $('#tt').datagrid({
                 title: '工具编号列表', //表格标题
                 url: 'GetNum.ashx', //请求数据的页面
                 sortName: 'num_name', //排序字段
                 idField: 'toolsNum_id', //标识字段,主键
                 iconCls: '', //标题左边的图标
                 width: '100%', //宽度
                 //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                 nowrap: false, //是否换行，True 就会把数据显示在一行里
                 striped: true, //True 奇偶行使用不同背景色
                 collapsible: false, //可折叠
                 singleSelect: true,
                 sortOrder: 'desc', //排序类型
                 remoteSort: true, //定义是否从服务器给数据排序
                 fitColumns: true,
                 method: 'post',
                 columns: [[
                     { field: 'ckb', checkbox: true },
                     { title: '名称', field: 'num_name', width: 150 },
                     { title: '监测工具', field: 'tools_name', width: 150 }

                 ]],
                 toolbar: "#tab_toolbar",
                 queryParams: { "action": "query" },
                 pagination: true, //是否开启分页
                 pageNumber: 1, //默认索引页
                 pageSize: 20, //默认一页数据条数
                 rownumbers: true //行号
             });
         }
         //初始化搜索框
         function InitSearch() {
             $("#ipt_search").combobox({
                 url: '../monitorTools/GetTools.ashx?action=ddllist',
                 valueField: 'tools_id',
                 textField: 'tools_name',
                 panelHeight: 'auto',
                 editable: false,
                 onLoadSuccess: function () {
                     if (cadd == "") {
                         var cdata = $('#ipt_search').combobox('getData');
                         $("#tools_id").combobox({
                             data: cdata,
                             //url: '../monitorTools/GetTools.ashx?action=ddllist&a=a',
                             valueField: 'tools_id',
                             textField: 'tools_name',
                             panelHeight: 'auto',
                             editable: false,
                             onLoadSuccess: function () {
                                 
                             }
                         });
                         var txt = JSON.stringify(cdata);
                         var acdata = JSON.parse(txt);                         
                         acdata.unshift({ "tools_name": "全部", "tools_id": "0" });
                         cadd = "a";
                         $("#ipt_search").combobox('loadData', acdata);

                     }
                     else {
                         $("#ipt_search").combobox('select', 0);
                     }
                 }
             });
             
            
         }
         function newUser() {
             //清空内容  
             $('#fm').form('clear');
             var data = $('#tools_id').combobox('getData');
             if (data.length > 0)
                 $("#tools_id").combobox('select', data[0].tools_id);
             $('#dlg').dialog('open').dialog('setTitle', '添加工具编号');
             document.getElementById("test").value = "add";
         }

         function editUser() {

             var row = $('#tt').datagrid('getSelected');
             if (row == null) {
                 $.messager.alert("提示", "请选择要修改的行！", "info");
             }
             if (row) {
                 $('#dlg').dialog('open').dialog('setTitle', '修改工具编号');
                 $('#tools_id').combobox('select', row.tools_id);
                 document.getElementById("test").value = "modify";
                 $('#fm').form('load', row);
             }
         }
         //添加        
         function saveUser() {
             var test = document.getElementById("test").value;
             var f = $('#fm');
             if (test == "add") {
                 f.form('submit', {
                     url: "GetNum.ashx?action=" + test,
                     onSubmit: function () {
                         return $(this).form('validate');
                     },
                     success: function (result) {
                         if (result.indexOf("T") == 0) {
                             $('#dlg').dialog('close');
                             $.messager.alert("提示", "恭喜您，信息添加成功", "info");
                             $('#tt').datagrid('reload');
                         }
                         else if ((result.indexOf("F") == 0)) {
                             $.messager.alert("提示", "添加失败，请重新操作！", "info");
                             return;
                         }
                         else if ((result.indexOf("L") == 0)) {
                             $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                             top.location = '/index.aspx';
                             return;
                         }
                     }
                 });

             } else {

                 $('#fm').form('submit', {
                     url: "GetNum.ashx?action=" + test,
                     onSubmit: function () {
                         return $(this).form('validate');
                     },
                     success: function (result) {
                         if (result.indexOf("T") == 0) {
                             $('#dlg').dialog('close');
                             $('#tt').datagrid('clearSelections');
                             $.messager.alert("提示", "恭喜您，信息修改成功", "info");
                             $('#tt').datagrid('reload');

                         }
                         else if ((result.indexOf("F") == 0)) {
                             $.messager.alert("提示", "添加失败，请重新操作！", "info");
                             return;
                         }
                         else if ((result.indexOf("L") == 0)) {
                             $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                             top.location = '/index.aspx';
                             return;
                         }
                     }
                 });
             }
         }

         function removeUser() {
             var test = document.getElementById("test").value = "delete";
             var row = $('#tt').datagrid('getSelected');
             if (row == null) {
                 $.messager.alert("提示", "请选择要删除的行！", "info");
             }
             if (row) {
                 $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                     if (r) {
                         $('#fm').form('submit', {
                             url: 'GetNum.ashx?toolsNum_id=' + row.toolsNum_id + "&action=" + test,
                             onSubmit: function () {
                                 //return $(this).form('validate');  
                             },
                             success: function (result) {
                                 if (result.indexOf("T") == 0) {
                                     $('#dlg').dialog('close');
                                     $('#tt').datagrid('clearSelections'); //清空选中的行  
                                     $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                     //alert('恭喜您，信息删除成功！')  
                                     // close the dialog  
                                     $('#tt').datagrid('reload');
                                     //$('#fm').form('submit');

                                 }
                                 else if ((result.indexOf("F") == 0)) {
                                     $.messager.alert("提示", "添加失败，请重新操作！", "info");
                                     return;
                                 }
                                 else if ((result.indexOf("L") == 0)) {
                                     $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                     top.location = '/index.aspx';
                                     return;
                                 }
                             }
                         });
                     }
                 })
             }
         }
         function getQueryParams(queryParams) {
             var StartTime = $("#ipt_search").combobox("getValue");             
             queryParams.ipt_search = StartTime;             
             return queryParams;

         }
         //增加查询参数，重新加载表格  
         function reloadgrid() {
             var queryParams = $('#tt').datagrid('options').queryParams;
             getQueryParams(queryParams);
             $('#tt').datagrid('options').queryParams = queryParams;
             $("#tt").datagrid('reload');
         }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="tt">
    </table>
    <div id="tab_toolbar" style="padding: 4px;">
        <table cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>

                <td style="padding-left: 2px">


                    <a href="#" onclick="newUser();" id="a_add"
                        class="easyui-linkbutton" iconcls="icon-add">添加</a>
                    <a href="javascript:void(0)" onclick="editUser() " class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
                    <a href="#" onclick="removeUser();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除</a>
<input id="ipt_search" type="text" />
                    <a href="#" onclick="reloadgrid();" id="a_search"
                        class="easyui-linkbutton" iconcls="icon-search">查找</a>
                </td>
                <td style="text-align: right; padding-right: 15px">
                    
                    
                </td>
            </tr>
        </table>
    </div>
    <div id="dlg" class="easyui-dialog" style="width: 400px; height: auto; padding: 10px 20px"
        data-options="closed:true,buttons:'#dlg-buttons',shadow:false">       
        
        <form id="fm" method="post">            
            <div class="fitem">
                <label>类别名称：</label>
                <input id="tools_id"  name="tools_id" type="text" style="width:100px;" />
                <input name="Test" id="test" type="hidden" />
                <input name="toolsNum_id" id="toolsNum_id" type="hidden" />
            </div>
            <div class="fitem">
                <label>工具编号：</label>
                <input id="num_name" name="num_name" />                
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
    </div>    
     
</asp:Content>